using System;

namespace Columbus.Tests.Features
{
    public class TransientStoreMock : ITransientStore
    {
        private readonly ITransientStore defaultImplementation;

        public TransientStoreMock(ITransientStore defaultImplementation)
        {
            this.defaultImplementation = defaultImplementation;
        }

        public void Save<T>(T obj, string key, params Type[] knownTypes)
        {
            defaultImplementation.Save(obj, key, knownTypes);
            if (typeof(T) == typeof(ViewState) && !key.Contains(NavigationAppication.ShellFileIdentifier))
                LastSavedViewState = obj as ViewState;
        }

        public T Load<T>(string key, params Type[] knownTypes)
        {
            return defaultImplementation.Load<T>(key, knownTypes);
        }

        public void Remove(string keyPattern)
        {
            defaultImplementation.Remove(keyPattern);
            StorageCleared = true;
        }

        public bool StorageCleared { get; set; }

        public ViewState LastSavedViewState { get; set; }
    }
}